#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/wait.h>

void pr_exit(int status) {
	if (WIFEXITED(status)) {
		printf("normal termination, exit status = %d\n", WEXITSTATUS(status));
	} 
	else if (WIFSIGNALED(status)) {
		printf("abnormal termination, signal number = %d\n", WTERMSIG(status));
	}
	else if (WIFSTOPPED(status)) {
		printf("child stopped, signal number = %d\n", WSTOPSIG(status));
	}
}

int main() {
	int status;

	if ((status=system("date")) < 0) {
		printf("system error: %s\n", strerror(errno));
		return -1;
	}
	pr_exit(status);

	if ((status=system("nosuchcommand")) < 0) {
		printf("system error: %s\n", strerror(errno));
		return -1;
	}
	pr_exit(status);

	if ((status=system("who; exit 44")) < 0) {
		printf("system error: %s\n", strerror(errno));
		return -1;
	}
	pr_exit(status);

	return 0;
}